package org.ehe.finance.currency.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.core.validate.AddGroup;
import org.ehe.common.core.validate.EditGroup;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.ehe.finance.currency.domain.bo.ErpFinanceCurrencyBo;
import org.ehe.finance.currency.domain.vo.ErpFinanceCurrencyVo;
import org.ehe.finance.currency.service.ErpFinanceCurrencyService;
import org.ehe.finance.subject.domain.bo.ErpFinanceAccountSubjectBo;
import org.ehe.finance.subject.domain.vo.ErpFinanceAccountSubjectVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *  币种控制器
 * @author :zhangnn
 * @className :ErpFinanceCurrencyController
 * @description: TODO
 * @date 2025-08-26 17:00:58
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/erp/finance/currency")
public class ErpFinanceCurrencyController extends BaseController {

    private final ErpFinanceCurrencyService financeCurrencyService;

    /**
     * 分页
     * @param bo
     * @param pageQuery
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo<ErpFinanceCurrencyVo> list(ErpFinanceCurrencyBo bo, PageQuery pageQuery) {
        return financeCurrencyService.queryPageList(bo, pageQuery);
    }

    /**
     * 新增币种
     */
    @Log(title = "新增币种", linkType = "finance", businessType = BusinessType.INSERT, idField = "id", nameField = "currencyName")
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpFinanceCurrencyBo bo) {
        return toAjax(financeCurrencyService.insertByBo(bo));
    }

    /**
     * 修改币种
     */
    @Log(title = "修改币种", linkType = "finance", businessType = BusinessType.UPDATE, idField = "id", nameField = "currencyName")
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpFinanceCurrencyBo bo) {
        return toAjax(financeCurrencyService.updateByBo(bo));
    }

    /**
     * 删除币种
     * @param id
     * @return
     */
    @Log(title = "删除币种", linkType = "finance", businessType = BusinessType.DELETE, idField = "id", nameField = "id")
    @PostMapping("/delete/{id}")
    public R<Void> delete(@PathVariable Long id) {
        return toAjax(financeCurrencyService.deleteById(id));
    }


    /**
     * 检查币种编码唯一性
     */
    @GetMapping("/checkCodeUnique")
    public boolean checkCodeUnique(String subjectCode, Long id) {
        return financeCurrencyService.checkCurrencyCodeUnique(subjectCode, id);
    }

}
